import React, { Component } from 'react';
import Image from 'react-uwp/Image';
import { PAYSTATE as STATE, ACTIONSTATE as ACTION } from '../../utils/constant';
import NoData from '../common/NoData';
import { Table } from 'antd';
import moment from 'moment';
const Column = Table;
export default class Order extends Component {
  constructor(props) {
    super(props);
  }
  componentDidMount() {
    // const { getOrderList } = this.props;
    // getOrderList();
  }
  renderBaseInfo = (text, item) => {
    const { title, imgs } = item;
    let subTitle = title;
    if (title.length > 48) {
      subTitle = title.substring(0, 47) + '...';
    }
    return (
      <div className="dfc aHelper">
        <div className="dfrsc">
          <div className="orderImg">
            <Image className="imgCover" src={imgs[0]} />
          </div>
          <div className="orderTitle" title={title}>
            {subTitle}
          </div>
        </div>
      </div>
    );
  };
  renderPrice = (text, item) => {
    const { state, price } = item;
    return (
      <div>
        {state == 1 ? (
          <p className="cred2 f20">
            <small className="cred2 ">￥</small>
            {price}
            <small className="c55">起</small>
          </p>
        ) : (
          <p className="fnormal">已失效</p>
        )}
      </div>
    );
  };
  render() {
    const {
      loading,
      list,
      pagination,
      deleteItem,
      onSelectChange,
      selectedRowKeys
    } = this.props;
    const rowSelection = { selectedRowKeys, onChange: onSelectChange };
    return (
      <div>
        {loading || (list && list.length > 0) ? (
          <Table
            className="orderTable"
            loading={loading}
            dataSource={list}
            pagination={pagination}
            rowSelection={rowSelection}
          >
            <Column
              title="标题"
              dataIndex="baseInfo"
              key="baseInfo"
              render={(text, record) => this.renderBaseInfo(text, record)}
            />

            <Column
              align="center"
              title="价格"
              width={200}
              dataIndex="price"
              key="price"
              render={(text, record) => this.renderPrice(text, record)}
            />

            <Column
              align="center"
              title="操作"
              width={200}
              dataIndex="action"
              key="action"
              render={(text, record) => (
                <a
                  style={{ color: '#FF6131' }}
                  onClick={() => deleteItem(record)}
                >
                  删除
                </a>
              )}
            />
          </Table>
        ) : (
          <div>
            <NoData iconClass="icon-nodata-topic" text="暂无收藏" />
          </div>
        )}
      </div>
    );
  }
}
